home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 January: Mac OS SDK / Dev.CD Jan 99 SDK1.toast / Development Kits / Apple Color OneScanner SDK / Scan Image 1.0 / Source / aevt.c next >
Encoding:
C/C++ Source or Header  |  1996-08-24  |  4.2 KB  |  171 lines  |  [TEXT/MPCC]

  1. /*************************************************************************************
  2. #
  3. #        aevt.c
  4. #
  5. #        Apple events handler.
  6. #
  7. #        Author(s):     Michael Marinkovich
  8. #                    Apple Developer Technical Support
  9. #                    marink@apple.com
  10. #
  11. #        Modification History: 
  12. #
  13. #            4/3/96        MWM     Initial coding                     
  14. #
  15. #        Copyright © 1992-96 Apple Computer, Inc., All Rights Reserved
  16. #
  17. #
  18. #        You may incorporate this sample code into your applications without
  19. #        restriction, though the sample code has been provided "AS IS" and the
  20. #        responsibility for its operation is 100% yours.  However, what you are
  21. #        not permitted to do is to redistribute the source as "DSC Sample Code"
  22. #        after having made changes. If you're going to re-distribute the source,
  23. #        we require that you make it clear in the source that the code was
  24. #        descended from Apple Sample Code, but that you've made changes.
  25. #
  26. *************************************************************************************/
  27.  
  28. #include <AppleEvents.h>
  29. #include <Windows.h>
  30.  
  31. #include "App.h"
  32. #include "Proto.h"
  33.  
  34.  
  35. //----------------------------------------------------------------------
  36. //    Globals
  37. //----------------------------------------------------------------------
  38.  
  39. extern Boolean        gDone;
  40.  
  41.  
  42. //----------------------------------------------------------------------
  43. //
  44. //    AEInit - initialize all the core apple events
  45. //
  46. //
  47. //----------------------------------------------------------------------
  48.  
  49. OSErr AEInit(void)
  50. {    
  51.     OSErr        err = noErr;
  52.                     
  53.                                 //    install auto Open App
  54.     err = AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, 
  55.                                 NewAEEventHandlerProc(DoAEOpenApp), 0L, false );
  56.                                                     
  57.     if (err == noErr)            // install auto Quit App
  58.         err = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, 
  59.                                     NewAEEventHandlerProc(DoAEQuitApp), 0L, false );
  60.         
  61.     if (err == noErr)            // install auto Open Document
  62.         err = AEInstallEventHandler(kCoreEventClass,kAEOpenDocuments,
  63.                                     NewAEEventHandlerProc(DoAEOpenDoc),0L,false);
  64.                                                         
  65.     if (err == noErr)            // install auto Print Document
  66.         err = AEInstallEventHandler(kCoreEventClass,kAEPrintDocuments,
  67.                                     NewAEEventHandlerProc(DoAEPrintDoc),0L,false);
  68.     
  69.                             
  70.     return err;
  71.                                                 
  72. }
  73.  
  74.  
  75. //----------------------------------------------------------------------
  76. //
  77. //    DoAEOpenApp - called by the Finder at launch time
  78. //
  79. //
  80. //----------------------------------------------------------------------
  81.  
  82. pascal OSErr DoAEOpenApp(AppleEvent *event,AppleEvent reply,long refCon)
  83. {
  84.     #pragma unused( event, reply, refCon )
  85.  
  86.                         
  87.     return noErr;
  88.         
  89. }
  90.  
  91.  
  92. //----------------------------------------------------------------------
  93. //
  94. //     DoAEQuitApp -    called when the Finder asks app to quit
  95. //
  96. //
  97. //----------------------------------------------------------------------
  98.  
  99. pascal OSErr DoAEQuitApp(AppleEvent *event,AppleEvent reply,long refCon)
  100. {
  101.     #pragma unused( event, reply, refCon )
  102.  
  103.     // set the global quit flag
  104.     gDone = true;
  105.     
  106.     return noErr;
  107.         
  108. }
  109.  
  110.  
  111. //----------------------------------------------------------------------
  112. //
  113. //    DoAEOpenDoc - called when the Finder asks app to open a document
  114. //
  115. //
  116. //----------------------------------------------------------------------
  117.  
  118. pascal OSErr DoAEOpenDoc(AppleEvent *event,AppleEvent reply,long refCon)
  119. {
  120.     #pragma unused( reply, refCon )
  121.     
  122.  
  123.     return noErr;
  124.  
  125. }
  126.                 
  127.                                         
  128. //----------------------------------------------------------------------
  129. //
  130. //    DoAEPrintDoc - called when the Finder asks app to print a document
  131. //
  132. //
  133. //----------------------------------------------------------------------
  134.  
  135. pascal OSErr DoAEPrintDoc(AppleEvent *event,AppleEvent reply,long refCon)
  136. {
  137.     #pragma unused( reply, refCon )
  138.     
  139.  
  140.     return noErr;
  141.  
  142. }
  143.  
  144.  
  145. //----------------------------------------------------------------------
  146. //
  147. //    GotAEParams - make sure we got proper AE params for an Open 
  148. //                  Document from the Finder
  149. //
  150. //----------------------------------------------------------------------
  151.  
  152. OSErr GotAEParams(AppleEvent *appleEvent)
  153. {
  154.     OSErr            err;
  155.     DescType        type;
  156.     Size            size;
  157.     
  158.     err = AEGetAttributePtr(appleEvent,keyMissedKeywordAttr,
  159.                             typeWildCard,&type,nil,0,&size);
  160.                                             
  161.     if (err == errAEDescNotFound)
  162.         return(noErr);
  163.     
  164.     else
  165.         if (err == noErr)
  166.             return(errAEEventNotHandled);
  167.     
  168.     return err;
  169.  
  170.